<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/js/plugins/jquery/jquery.min.js"></script>
</head>
<body>
    <h1>评论</h1>
    <form>
        <input type="hidden" th:value="${orderId}" id="order">
        商品名称：<span th:text="${item.title}" id="titleId"></span><br><br>
        打分：
            <select id="scoreId">
                <option value="1">★</option>
                <option value="2">★★</option>
                <option value="3">★★★</option>
                <option value="4">★★★★</option>
                <option value="5">★★★★★</option>
            </select><br><br>
        评价：<textarea id="contentId" rows="5" cols="20"></textarea><br><br>
        <input type="button" value="提交评价" onclick="addevaluate()">
    </form>
</body>
</html>
<script th:inline="javascript">

    var user = [[${user}]];
    var item = [[${item}]];
    function addevaluate(){
        var orderId = $("#order").val();
        var userId = user.id;//用户id
        var username = user.username;//用户名称
        var options = $("#scoreId option:selected");
        var score = options.val();//打分
        var content = $("#contentId").val();//评论
        var goodsId = item.goodsId;//商品id
        var title = item.title;//商品名称
        var spec = item.spec;//规格


        $.ajax({
            url:"/userhome/addevaluate",
            type:"post",
            dataTtpe:"json",
            data:{userId:userId,username:username,score:score,content:content,goodsId:goodsId,title:title,spec:spec,orderId:orderId},
            async:false,
            success:function(data){
                if(data.code==200){
                    location.href="/userhome/toOrderEvaluate";
                }
            },
            error:function(){
                alert("系统异常");
            }
        })
    }
</script>